package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Copyfright(C),2022-2022,复兴元宇科技有限公司
 * FileName:HelloMVCCtl
 * Author:yz
 * Date:2022/3/14 9:23 上午
 * Description:
 * History:
 * <author>  <time> <version> <desc>
 * 作者       时间    版本      描述
 */
@Controller
public class HelloMVCCtl {
    @RequestMapping("/helloword")
    public String helloWord(Model model) throws Exception {
        model.addAttribute("nav", "Hello spring Boot !,i am mvc struct ");
        //视图view,的位置和名称。视图位于example文件夹下，视图的名字是hello.html
        return "example/hello";
    }

    @RequestMapping(value = "/product/{id}", method = RequestMethod.GET)
    public String getProduct(@PathVariable("id") String id, Model model) throws Exception {
        Product product = new Product();
        product.setId(id);
        product.setDescribe("this product is perfect and it id is " + id);
        product.setName("product name");
        product.setPrice(998.0f);
        model.addAttribute("model", product);
        return "product/show";
    }

    //    等号接收测试
    @RequestMapping("/addproduct")
    public String getProductWithEqual(String productname, Model model) throws Exception {
        System.out.println(productname);
        model.addAttribute("productname", productname);
        return "product/addname";
    }
 

}
